package sync;

import com.qijian.QiJianApplication;
import com.qijian.business.domain.ProductAttribute;
import com.qijian.business.domain.ProductAttributeItem;
import com.qijian.business.domain.ProductAttributeItemDetail;
import com.qijian.business.service.*;
import com.qijian.common.core.domain.entity.SysDictData;
import com.qijian.common.utils.sync.GetKingDeeData;
import com.qijian.maindata.domain.Project;
import com.qijian.maindata.service.IItemGetDetailService;
import com.qijian.purchase.mapper.PurchaseContractDetailMapper;
import com.qijian.purchase.service.IPurchaseContractDetailService;
import com.qijian.purchase.service.IPurchaseContractService;
import com.qijian.system.service.ISysDictDataService;
import com.qijian.tool.domain.CommonClassify;
import com.qijian.tool.service.ICommonClassifyService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;


@SpringBootTest(classes = QiJianApplication.class)
public class KingDeeSync {
    @Autowired
    private com.qijian.sync.KingDeeSync kingDeeSync;
    @Autowired
    private com.qijian.sync.KingDeeSyncFin kingDeeSyncFin;
    @Autowired
    private com.qijian.sync.KingDeeSyncPurchase kingDeeSyncPurchase;
    @Autowired
    private com.qijian.sync.KingdeeSyncInventory kingDeeSyncInventory;
    @Autowired
    private com.qijian.sync.KingDeeSyncManufacture kingDeeSyncManufacture;
    @Autowired
    private IContractSalesService salesService;
    @Autowired
    private IContractSalesDetailService salesDetailService;
    @Autowired
    private IInventoryService inventoryService;
    @Autowired
    private IInventoryDetailService inventoryDetailService;
    @Autowired
    private ICustomerService customerService;
    @Autowired
    private ICommonClassifyService commonClassifyService;
    @Autowired
    private ISupplierService supplierService;
    @Autowired
    private IProjectService projectService;
    @Autowired
    private IProductAttributeService productAttributeService;
    @Autowired
    private ISysDictDataService dictDataService;
    @Autowired
    private IProductAttributeItemService productAttributeItemService;
    @Autowired
    private IProductAttributeItemDetailService productAttributeItemDetailService;
    @Autowired
    private IPurchaseContractService purchaseContractService;
    @Autowired
    private IPurchaseContractDetailService purchaseContractDetailService;
    @Autowired
    private IItemGetService itemGetService;
    @Autowired
    private IItemGetDetailService itemGetDetailService;
    @Autowired
    private PurchaseContractDetailMapper purchaseContractDetailMapper;


    static SimpleDateFormat sdf;
    static SimpleDateFormat sdf1;
    static GetKingDeeData kingDee;

    @BeforeEach
    void before() {
        sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        sdf1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
        kingDee = new GetKingDeeData();
    }

    static class util {
        protected static Long getLong(Object val) {
            if (val == null) return null;
            return Long.valueOf(getStr(val));
        }

        protected static Integer getInt(Object val) {
            if (val == null) return null;
            return getBigDecimal(val).intValue();
        }

        protected static String getStr(Object val) {
            if (ObjectUtils.isEmpty(val)) return null;
            return String.valueOf(val);
        }

        protected static Boolean getBool(Object val) {
            if (val == null) return null;
            return Boolean.parseBoolean(getStr(val));
        }

        protected static BigDecimal getBigDecimal(Object val) {
            if (val == null) return null;
            return new BigDecimal(Objects.requireNonNull(getStr(val))).setScale(4, BigDecimal.ROUND_HALF_UP);
        }

        protected static BigDecimal getBigDecimal(Object val, int scale) {
            if (val == null) return null;
            return new BigDecimal(Objects.requireNonNull(getStr(val))).setScale(scale, BigDecimal.ROUND_HALF_UP);
        }
    }

    @Test
    void dateParse() {
        try {
            System.out.println(sdf.parse("2021-12-14T14:42:39.317"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Test
    void saleContract() {
        kingDeeSync.saleContract();
    }

    @Test
    void purmInbound() {
        kingDeeSync.purmInbound();
    }



    @Test
    void logisticsDelivery() {
        kingDeeSync.logisticsDelivery();
    }


    @Test
    void accountPaid() {
        kingDeeSync.accountPaid();
    }


    @Test
    public void customer() {
        List<Map<String, Object>> data = kingDee.getCustomer();
        Map<String, Customer> unique = new HashMap<>();

        data.forEach(item -> {
            String name = String.valueOf(item.get("FName"));
            if (!unique.containsKey(name)) {
                try {
                    Customer customer = new Customer();
                    customer.setId(Long.valueOf(String.valueOf(item.get("FCUSTID"))));
                    customer.setName(name);
                    customer.setNumber(String.valueOf(item.get("FNumber")));
                    customer.setCreateBy(String.valueOf(item.get("FCreatorId.FName")));
                    customer.setCreateTime(sdf.parse(String.valueOf(item.get("FCreateDate"))));
                    customer.setUpdateBy(String.valueOf(item.get("FModifierId.FName")));
                    customer.setUpdateTime(sdf.parse(String.valueOf(item.get("FModifyDate"))));
                    unique.put(name, customer);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        });
        customerService.saveBatch(unique.values());
    }

    /**
     * 物料分类同步
     */
    @Test
    void itemClassify() {
        List<Map<String, Object>> data = kingDee.getItemClassify();
        List<CommonClassify> classifys = new ArrayList<CommonClassify>((int) ((data.size() / 0.75) + 1));

        data.forEach(item -> {
            try {
                CommonClassify classify = new CommonClassify();
                classify.setId(Long.valueOf(String.valueOf(item.get("FID"))));
                classify.setName(String.valueOf(item.get("FName")));
                classify.setCode(String.valueOf(item.get("FNumber")));
                classify.setClassifyType("item");
                classify.setAncestors(String.valueOf(item.get("FFullParentId")).replaceAll("\\.", ","));
                String top = String.valueOf(item.get("FFullParentId"));
                int count = StringUtils.countMatches(top, ".");
                if (count <= 1)
                    top = top.replace(".", "");
                else {
                    top = top.substring(1, StringUtils.ordinalIndexOf(top, ".", 2));
                }
                if (StringUtils.isNotBlank(top))
                    classify.setTopClassifyId(Long.valueOf(top));
                else
                    classify.setTopClassifyId(classify.getId());
                classify.setParentClassifyId(Long.valueOf(String.valueOf(item.get("FParentId"))));
                classifys.add(classify);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        });
        commonClassifyService.saveBatch(classifys);
    }

    /**
     * 供应商
     */
    @Test
    void supplier() {
//        List<Map<String, Object>> data = kingDee.getSupplier(null);
//        List<Supplier> suppliers = new ArrayList<Supplier>((int) ((data.size() / 0.75) + 1));
//
//        data.forEach(item -> {
//            try {
//                Supplier supplier = new Supplier();
//                supplier.setId(Long.valueOf(String.valueOf(item.get("FSupplierId"))));
//                supplier.setName(String.valueOf(item.get("FName")));
//                supplier.setNumber(String.valueOf(item.get("FNumber")));
//                supplier.setLevel(1);
//                supplier.setCreateBy(String.valueOf(item.get("FCreatorId.FName")));
//                supplier.setCreateTime(sdf.parse(String.valueOf(item.get("FCreateDate"))));
//                supplier.setUpdateBy(String.valueOf(item.get("FModifierId.FName")));
//                supplier.setUpdateTime(sdf.parse(String.valueOf(item.get("FModifyDate"))));
//                suppliers.add(supplier);
//            } catch (Exception ex) {
//                ex.printStackTrace();
//            }
//        });
//        supplierService.saveBatch(suppliers);
    }


    @Test
    public void projectNo() {
        List<Map<String, Object>> data = kingDee.getProjectNo();


        List<Project> all = projectService.list();
        Map<String, Project> allMap = all.stream().collect(Collectors.toMap(p -> p.getProjectNo() + p.getMachineNo(), a -> a, (k1, k2) -> k1));
        Map<String, Map> dataMap = data.stream().collect(Collectors.toMap(m -> m.get("F_ora_Text2").toString() + m.get("F_ora_Text3").toString(), a -> a, (k1, k2) -> k1));

        dataMap.keySet().removeIf(allMap::containsKey);

        List<Project> projects = new ArrayList<Project>((int) ((dataMap.size() / 0.75) + 1));


        dataMap.values().forEach(v -> {
            try {
                Project project = new Project();
                project.setIsDel(false);
                project.setProjectNo(String.valueOf(v.get("F_ora_Text2")));
                project.setProjectName(String.valueOf(v.get("F_ora_Text1")));
                project.setMachineNo(String.valueOf(v.get("F_ora_Text3")));
                project.setProjectType("2");
                project.setCreateBy(String.valueOf(v.get("FCreatorId.FName")));
                project.setCreateTime(sdf.parse(String.valueOf(v.get("FCreateDate"))));
                project.setUpdateBy(String.valueOf(v.get("FModifierId.FName")));
                project.setUpdateTime(sdf.parse(String.valueOf(v.get("FModifyDate"))));
                String status = String.valueOf(v.get("FBILLSTATUS"));
                Integer state = null;
                switch (status) {
                    case "A":
                        state = 1;
                        break;
                    case "B":
                        state = 2;
                        break;
                    case "C":
                        state = 3;
                        break;
                    case "D":
                        state = 0;
                        break;
                    default:
                        break;
                }
                project.setStatus(state);
                project.setUserId(Long.valueOf(String.valueOf(v.get("F_BEQ_BASE2"))));
                projects.add(project);
            } catch (ParseException ex) {
                ex.printStackTrace();
            }
        });
        System.out.println(1);
        projectService.saveBatch(projects);
    }

    @Test
    void attribute() {
        //辅助属性
        List<Map<String, Object>> attribute = kingDee.getAttribute();
        List<ProductAttribute> productAttributeList = new ArrayList<>();

        attribute.forEach(a -> {
            try {
                ProductAttribute attr = new ProductAttribute();
                attr.setId(Long.valueOf(String.valueOf(a.get("FID"))));
                attr.setName(String.valueOf(a.get("FNAME")));
                attr.setCode(String.valueOf(a.get("FNUMBER")));
                attr.setType(String.valueOf(a.get("FVALUETYPE")).equals("1") ? "固定值" : "任意值");
                attr.setIsDisabled(!"A".equals((String) a.get("FFORBIDSTATUS")));
                attr.setCreateBy(String.valueOf(a.get("FCreatorId.FName")));
                attr.setCreateTime(sdf.parse(String.valueOf(a.get("FCreateDate"))));
                attr.setUpdateBy(String.valueOf(a.get("FModifierId.FName")));
                attr.setUpdateTime(sdf.parse(String.valueOf(a.get("FModifyDate"))));
                productAttributeList.add(attr);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        });
        productAttributeService.saveBatch(productAttributeList);
    }

//    @Test
//    void attributeValue() {
//        List<Map> attribute = kingDee.getAttributeValue();
//        Map<Long, ProductAttributeItem> d1 = new HashMap<>();
//        Map<Long, ProductAttributeItemDetail> d2 = new HashMap<>((int) (attribute.size() / 0.75 + 1));
//        attribute.forEach(a -> {
//            try {
//                if (!d1.containsKey(Long.valueOf(String.valueOf(a.get("FAuxPtyValueID"))))) {
//                    ProductAttributeItem attrItem = new ProductAttributeItem();
//                    attrItem.setId(Long.valueOf(String.valueOf(a.get("FAuxPtyValueID"))));
//                    attrItem.setItemId(Long.valueOf(String.valueOf(a.get("FMaterialId"))));
//                    attrItem.setItemName(String.valueOf(a.get("FMaterialId.FName")));
//                    attrItem.setItemCode(String.valueOf(a.get("FMaterialId.FNumber")));
//                    attrItem.setAttrId(Long.valueOf(String.valueOf(a.get("FMaterialAuxPropertyId"))));
//                    attrItem.setAttrName(String.valueOf(a.get("FMaterialAuxPropertyId.FName")));
//                    attrItem.setIsDisabled(!"A".equals(String.valueOf(a.get("FForbidStatus"))));
//                    attrItem.setIsPreInsert(Boolean.valueOf(String.valueOf(a.get("FIsSysPreInsert"))));
//                    attrItem.setCreateBy(String.valueOf(a.get("FCreatorId.FName")));
//                    attrItem.setCreateTime(sdf.parse(String.valueOf(a.get("FCreateDate"))));
//                    attrItem.setUpdateBy(String.valueOf(a.get("FModifierId.FName")));
//                    attrItem.setUpdateTime(sdf.parse(String.valueOf(a.get("FModifyDate"))));
//                    d1.put(attrItem.getId(), attrItem);
//                }
//                ProductAttributeItemDetail attrItemDetail = new ProductAttributeItemDetail();
//                attrItemDetail.setId(Long.valueOf(String.valueOf(a.get("FEntity_FEntryID"))));
//                attrItemDetail.setAttrItemId(Long.valueOf(String.valueOf(a.get("FAuxPtyValueID"))));
//                attrItemDetail.setInnerCode(String.valueOf(a.get("FAuxPtyId")));
//                attrItemDetail.setName(String.valueOf(a.get("FAuxPtyName")));
//                attrItemDetail.setNumber(String.valueOf(a.get("FAuxPtyNumber")));
//                attrItemDetail.setSort(Integer.valueOf(String.valueOf(a.get("FDisplaySeq"))));
//                attrItemDetail.setIsDisabled(Boolean.valueOf(String.valueOf(a.get("FIsDisable"))));
//                attrItemDetail.setIsSelect(Boolean.valueOf(String.valueOf(a.get("FIsSelect"))));
//                attrItemDetail.setIsDefault(Boolean.valueOf(String.valueOf(a.get("FIsDefault"))));
//
//                attrItemDetail.setCreateBy(String.valueOf(a.get("FCreatorId.FName")));
//                attrItemDetail.setCreateTime(sdf.parse(String.valueOf(a.get("FCreateDate"))));
//                attrItemDetail.setUpdateBy(String.valueOf(a.get("FModifierId.FName")));
//                attrItemDetail.setUpdateTime(sdf.parse(String.valueOf(a.get("FModifyDate"))));
//                d2.put(attrItemDetail.getId(), attrItemDetail);
//            } catch (Exception ex) {
//                ex.printStackTrace();
//            }
//        });
//        System.out.println(1);
//        productAttributeItemService.saveBatch(d1.values());
//        productAttributeItemDetailService.saveBatch(d2.values());
//    }

    @Test
    void attributeValue() {
        List<Map<String, Object>> itemAttr = kingDee.getItemAttr();
        Map<String, Map> itemAttrMap = itemAttr.stream().collect(Collectors.toMap(a -> a.get("FMATERIALID") + "-" + a.get("FAuxPropertyId"), a -> a));
        List<Map<String, Object>> attribute = kingDee.getAttributeValue();
        List<ProductAttributeItem> d1 = new ArrayList<>((int) (itemAttr.size() / 0.75 + 1));
        List<ProductAttributeItemDetail> d2 = new ArrayList<>((int) (attribute.size() / 0.75 + 1));
        itemAttr.forEach(a -> {
            try {
                ProductAttributeItem attrItem = new ProductAttributeItem();
                attrItem.setId(Long.valueOf(String.valueOf(a.get("FEntityAuxPty_FEntryID"))));
                attrItem.setItemId(Long.valueOf(String.valueOf(a.get("FMATERIALID"))));
                attrItem.setItemName(String.valueOf(a.get("FName")));
                attrItem.setItemCode(String.valueOf(a.get("FNumber")));
                attrItem.setAttrId(Long.valueOf(String.valueOf(a.get("FAuxPropertyId"))));
                attrItem.setAttrName(String.valueOf(a.get("FAuxPropertyId.FName")));
                attrItem.setIsDisabled(!Boolean.parseBoolean(String.valueOf(a.get("FIsEnable1"))));
                attrItem.setIsPreInsert(Boolean.valueOf(String.valueOf(a.get("FIsMustInput"))));
                attrItem.setCreateBy(String.valueOf(a.get("FCreatorId.FName")));
                attrItem.setCreateTime(sdf.parse(String.valueOf(a.get("FCreateDate"))));
                attrItem.setUpdateBy(String.valueOf(a.get("FModifierId.FName")));
                attrItem.setUpdateTime(sdf.parse(String.valueOf(a.get("FModifyDate"))));
                d1.add(attrItem);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        });
        attribute.forEach(a -> {
            try {
                ProductAttributeItemDetail attrItemDetail = new ProductAttributeItemDetail();
                attrItemDetail.setId(Long.valueOf(String.valueOf(a.get("FEntity_FEntryID"))));
                attrItemDetail.setAttrItemId(Long.valueOf(String.valueOf(itemAttrMap.get(a.get("FMaterialId") + "-" + a.get("FMaterialAuxPropertyId")).get("FEntityAuxPty_FEntryID"))));
                attrItemDetail.setInnerCode(String.valueOf(a.get("FAuxPtyId")));
                attrItemDetail.setName(String.valueOf(a.get("FAuxPtyName")));
                attrItemDetail.setNumber(String.valueOf(a.get("FAuxPtyNumber")));
                attrItemDetail.setSort(Integer.valueOf(String.valueOf(a.get("FDisplaySeq"))));
                attrItemDetail.setIsDisabled(Boolean.valueOf(String.valueOf(a.get("FIsDisable"))));
                attrItemDetail.setIsSelect(Boolean.valueOf(String.valueOf(a.get("FIsSelect"))));
                attrItemDetail.setIsDefault(Boolean.valueOf(String.valueOf(a.get("FIsDefault"))));
                attrItemDetail.setCreateBy(String.valueOf(a.get("FCreatorId.FName")));
                attrItemDetail.setCreateTime(sdf.parse(String.valueOf(a.get("FCreateDate"))));
                attrItemDetail.setUpdateBy(String.valueOf(a.get("FModifierId.FName")));
                attrItemDetail.setUpdateTime(sdf.parse(String.valueOf(a.get("FModifyDate"))));
                d2.add(attrItemDetail);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        });
        productAttributeItemService.saveBatch(d1);
        productAttributeItemDetailService.saveBatch(d2);
    }

    @Test
    void dict() {
        Map<String, String> FId_DictType = new HashMap<String, String>() {{
            put("5e589cdd76ebb6", "sys_thickness");//厚度
            put("5e589cb876ebb4", "sys_material");//材质
            put("5e589cee76ebc7", "sys_brand");//品牌
            put("5e589d0176ebc9", "sys_specifications");//规格型号
            put("5f59cb29043f23", "sys_packing");//包装方式
        }};

        List<SysDictData> dataList = new ArrayList<>();
        FId_DictType.forEach((key, value) -> {
            List<Map<String, Object>> data = kingDee.getDict(key);
            data.forEach(d -> {
                try {
                    SysDictData dictData = new SysDictData();
                    dictData.setDictLabel(String.valueOf(d.get("FDataValue")));
                    dictData.setDictValue(String.valueOf(d.get("FEntryID")));
                    dictData.setDictType(value);
                    dictData.setDictSort(Long.valueOf(String.valueOf(d.get("FSeq"))));
                    dictData.setListClass("default");
                    dictData.setStatus("A".equals(String.valueOf(d.get("FForbidStatus"))) ? "0" : "1");
                    dictData.setIsDefault(Boolean.parseBoolean(String.valueOf(d.get("FIsSysPreset"))) ? "Y" : "N");
                    dictData.setCreateBy(String.valueOf(d.get("FCreatorId.FName")));
                    dictData.setCreateTime(sdf.parse(String.valueOf(d.get("FCreateDate"))));
                    dictData.setUpdateBy(String.valueOf(d.get("FModifierId.FName")));
                    dictData.setUpdateTime(sdf.parse(String.valueOf(d.get("FModifyDate"))));
                    dataList.add(dictData);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            });

        });
        //辅助资料（字典）
        dictDataService.insertBatch(dataList);
    }

//    @Test
//    void purchaseContract() {
//        List<Map<String, Object>> purchaseOrder = kingDee.getPurchaseOrder();
//
//        Map<Long, PurchaseContract> contracts = new HashMap<>();
//        List<PurchaseContractDetail> contractDetails = new ArrayList<>((int) (purchaseOrder.size() / 0.75 + 1));
//        purchaseOrder.forEach(order -> {
//            Long fid = util.getLong(order.get("FID"));
//            try {
//                if (!contracts.containsKey(fid)) {
//                    PurchaseContract contract = new PurchaseContract();
//                    contract.setId(fid);
//                    contract.setNumber(util.getStr(order.get("FBillNo")));
//                    contract.setContractDate(sdf.parse(String.valueOf(order.get("FDate"))));
//                    contract.setType(util.getStr(order.get("FBillTypeID.FName")));
////                    contract.setBusinessType(util.getStr(order.get("FBusinessType")));
//                    contract.setSupplierId(util.getLong(order.get("FSupplierId")));
//                    contract.setSupplierName(util.getStr(order.get("FSupplierId.FName")));
//                    Integer status = null;
//                    switch (util.getStr(order.get("FDocumentStatus"))) {
//                        case "A":
//                            status = 1;//创建
//                            break;
//                        case "B":
//                            status = 2;//审核中
//                            break;
//                        case "C":
//                            status = 3;//已审核
//                            break;
//                        case "D":
//                            status = 4;//重新审核
//                            break;
//                        case "Z":
//                            status = 99;//暂存
//                            break;
//                    }
////                    contract.setsta(status);
//                    Integer confirmStatus = null;
//                    switch (util.getStr(order.get("FConfirmStatus"))) {
//                        case "A":
//                            confirmStatus = 0;//未确认
//                            break;
//                        case "B":
//                            confirmStatus = 1;//已确认
//                            break;
//                    }
////                    contract.setApprovalStatus(confirmStatus);
////                    contract.setBuyerId(util.getLong(order.get("FPurchaserId")));
////                    contract.setBuyerName(util.getStr(order.get("FPurchaserId.FName")));
////                    contract.setChargeUserId(util.getLong(order.get("FApproverId")));
////                    contract.setChargeUserName(util.getStr(order.get("FApproverId.FName")));
////                    contract.setChargeContactId(util.getLong(order.get("FProviderContactId")));
////                    contract.setChargeContactName(util.getStr(order.get("FProviderContactId.FName")));
////                    contract.setCreatorId(util.getLong(order.get("FCreatorId")));
////                    contract.setCreatorName(String.valueOf(order.get("FCreatorId.FName")));
////                    contract.setCreationDate(sdf.parse(String.valueOf(order.get("FCreateDate"))));
////                    contract.setTotalTax(util.getBigDecimal(order.get("FBillTaxAmount")));
////                    contract.setTotalAmount(util.getBigDecimal(order.get("FBillAmount")));
////                    contract.setContractAmount(util.getBigDecimal(order.get("FBillAllAmount")));
////                    contract.setTotalTaxLc(util.getBigDecimal(order.get("FBillTaxAmount_LC")));
////                    contract.setTotalAmountLc(util.getBigDecimal(order.get("FBillAmount_LC")));
////                    contract.setContractAmountLc(util.getBigDecimal(order.get("FBillAllAmount_LC")));
//                    contract.setCurrencyType(util.getStr(order.get("FSettleCurrId.FName")));
////                    contract.setExchangeRate(util.getBigDecimal(order.get("FExchangeRate")));
//                    contract.setCreateBy(String.valueOf(order.get("FCreatorId.FName")));
//                    contract.setCreateTime(sdf.parse(String.valueOf(order.get("FCreateDate"))));
//                    contract.setUpdateBy(String.valueOf(order.get("FModifierId.FName")));
//                    contract.setUpdateTime(sdf.parse(String.valueOf(order.get("FModifyDate"))));
//                    contract.setRemark(util.getStr(order.get("F_ora_LargeText")));
//                    contracts.put(fid, contract);
//                }
//                PurchaseContractDetail detail = new PurchaseContractDetail();
//                detail.setId(util.getLong(order.get("FPOOrderEntry_FEntryID")));
////                detail.setPurchaseContractId(fid);
////                detail.setSourceId(util.getLong(order.get("FPOOrderEntry_Link_FSBillId")));
////                detail.setSourceType(util.getStr(order.get("FSrcBillTypeId")));
////                detail.setProductId(util.getLong(order.get("FMaterialId")));
////                detail.setProductName(util.getStr(order.get("FMaterialId.FName")));
////                detail.setProductNumber(util.getStr(order.get("FMaterialId.FNumber")));
////                detail.setProductUnit(util.getStr(order.get("FUnitId.FName")));
////                detail.setCount(util.getInt(order.get("FQty")));
////                detail.setInboundCount(util.getInt(order.get("FStockInQty")));
//                detail.setUnitPrice(util.getBigDecimal(order.get("FPrice")));
//                detail.setTaxUnitPrice(util.getBigDecimal(order.get("FTaxPrice")));
////                detail.setDiscount(util.getBigDecimal(order.get("FEntryDiscountRate")));
//                detail.setTaxRate(util.getBigDecimal(order.get("FEntryTaxRate")));
////                detail.setArrivalDate(sdf.parse(String.valueOf(order.get("FDeliveryDate"))));
//                detail.setRemark(util.getStr(order.get("FEntryNote")));
////                detail.setTotalAmountNotTax(util.getBigDecimal(order.get("FEntryAmount")));
////                detail.setTotalAmountNotTaxLc(util.getBigDecimal(order.get("FAmount_LC")));
//                detail.setTax(util.getBigDecimal(order.get("FEntryTaxAmount")));
//                detail.setTaxLc(util.getBigDecimal(order.get("FTaxAmount_LC")));
//                detail.setTotalAmount(util.getBigDecimal(order.get("FAllAmount")));
//                detail.setTotalAmountLc(util.getBigDecimal(order.get("FAllAmount_LC")));
//
//                detail.setCreateBy(String.valueOf(order.get("FCreatorId.FName")));
//                detail.setCreateTime(sdf.parse(String.valueOf(order.get("FCreateDate"))));
//                detail.setUpdateBy(String.valueOf(order.get("FModifierId.FName")));
//                detail.setUpdateTime(sdf.parse(String.valueOf(order.get("FModifyDate"))));
//                contractDetails.add(detail);
//            } catch (Exception ex) {
//                ex.printStackTrace();
//            }
//        });
//        purchaseContractService.saveBatch(contracts.values(), 1000);
//        purchaseContractDetailService.saveBatch(contractDetails, 1000);
//    }

    @Test
    void item() {
        kingDeeSync.item();
    }

    @Test
    void accountReceived() {
        kingDeeSync.accountReceived();
    }

    @Test
    void accountAmount() {
        kingDeeSyncFin.accountAmount();
    }

    @Test
    void subjectType() {
        kingDeeSyncFin.subjectType();
    }

    @Test
    void subject() {
        kingDeeSyncFin.subject();
    }

    @Test
    void purchaseContract() {
        kingDeeSyncPurchase.purchaseContract();
    }

    @Test
    void purchaseRequisition() {
        kingDeeSyncPurchase.purchaseRequisition();
    }

    @Test
    void voucher() {
        kingDeeSyncFin.voucher();
//        kingDeeSyncFin.voucher(Lists.newArrayList("6603"));
    }

    @Test
    void accountPayable() {
        kingDeeSync.accountPayable();
    }

    @Test
    void accountReceivable() {
        kingDeeSync.accountReceivable();
    }

    @Test
    void paidApply() {
        kingDeeSyncFin.paidApply();
    }

    @Test
    void tl() {
        kingDeeSyncInventory.tl();
    }

    @Test
    void itemGet() {
        kingDeeSyncManufacture.itemGetAndReplenishAndEasy();
    }


    @Test
    void unit() {
        kingDeeSync.unit();
    }

    private Integer getBillStatus(Object obj) {
        Integer status = null;
        switch (Objects.requireNonNull(util.getStr(obj))) {
            case "A":
                status = 1;//创建
                break;
            case "B":
                status = 2;//审核中
                break;
            case "C":
                status = 3;//已审核
                break;
            case "D":
                status = 4;//重新审核
                break;
            case "Z":
                status = 99;//暂存
                break;
        }
        return status;
    }

}
